 $(document).ready(function() {
$("form :input").blur(function() {
		var $parent = $(this).parent();
		$parent.find(".tishi").remove();
		//进行下一步判断前把之前的结果清除

		//根据长度判断密码是否合法

		if($(this).is("#email")) {
			if(this.value=="") {
				var errorMsg = "输入常用邮箱，通过验证后可用于登录和找回密码";
				$parent.append("<span class='tishi pass_reg_err'>"+errorMsg+"</span>");
			}else if(this.value!="" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value)){
				var errorMsg = "请输入有效的邮箱格式";
				$parent.append("<span class='tishi pass_reg_err'>"+errorMsg+"</span>");
			}else{
				$parent.append("<span class='tishi pass_valid_right'></span>");
			}
		}
		//邮箱验证

		if($(this).is("#password")) {
			if(this.value=="" || this.value.length < 6 || this.value.length > 14) {
				var errorMsg = "密码长度6~14位，字母区分大小写";
				$parent.append("<span class='tishi pass_reg_err'>"+errorMsg+"</span>");
			}else if($("#repassword").val() != "" && this.value != $("#repassword").val()){
				var errorMsg = "密码和确认密码不一致";
				$parent.append("<span class='tishi pass_reg_err'>"+errorMsg+"</span>");
			}else{
				$parent.append("<span class='tishi pass_valid_right'></span>");
			}
		}

		if($(this).is("#repassword")) {
			if(this.value=="") {
				var errorMsg = "请输入确认密码";
				$parent.append("<span class='tishi pass_reg_err'>"+errorMsg+"</span>");
			}else if(this.value != $("#password").val()){
				var errorMsg = "密码和确认密码不一致";
				$parent.append("<span class='tishi pass_reg_err'>"+errorMsg+"</span>");
			}else{
				$parent.append("<span class='tishi pass_valid_right'></span>");
			}
		}


		if($(this).is("#isagree")) {
			if($(this).attr('checked')==undefined) {
				var errorMsg = "您还没有接受用户协议";
				$parent.append("<span class='tishi pass_reg_err'>"+errorMsg+"</span>");
			}else{
				$parent.append("<span class='tishi pass_valid_right'></span>");
			}
		}
		
	}).keyup(function() {
		$(this).triggerHandler("blur");
	}).focus(function() {
		$(this).triggerHandler("blur");
	});
	//在敲击键盘和输入框获取焦点时用triggerHandler()方法模拟blur事件，来触发对本项的验证
	$("#send").mouseover(function(){
		$(this).removeClass("pass_reg_submit_default");
		$(this).addClass("pass_reg_submit_hover");
	});
	$("#send").mouseout(function(){
		$(this).removeClass("pass_reg_submit_hover");
		$(this).addClass("pass_reg_submit_default");
	});


	$("#send").click(function() {		
		$("form :input").trigger("blur");

		var errorNum = $("form .pass_reg_err").length;
		if(errorNum) {
			return false;
		}
		var obj = swfobject.getObjectById("preload");
		var uid = $("#email").val();
		var pass = $("#password").val();
		var recomm = swfobject.getQueryParamValue("recommId");

		var paras = {id:uid,pass:pass,recomId:recomm,version:Game.versionstr,logoBarId:'logoBar1.png'};
		obj.registerFunc(paras);
	});
	//点击“提交”按钮时根据表单内错误信息的数量判断是否全部填写正确


 });

 function showConnectSuc(){
	enableSubmitBtn();
 }

 function disableSubmitBtn(){
	$("#send").removeClass("pass_reg_submit_default");
	$("#send").addClass("pass_reg_submit_disable");
	$("#send").attr("value","加载中...");
	$("#send").attr("disabled","disabled");
 }

 function enableSubmitBtn(){
	$("#send").removeClass("pass_reg_submit_disable");
	$("#send").addClass("pass_reg_submit_default");
	$("#send").attr("value","注册");
	$("#send").removeAttr("disabled");
 }

  function loadMainPage(){
	disableSubmitBtn();
	$("#content_reg").fadeOut("fast",function(){
		$(this).empty();
		$("body").css({ backgroundColor: "#cccccc",textAlign:"center"});
		$("#doc").addClass("route-front");
		var obj = swfobject.getObjectById("preload");
		$(obj).css({ width: "790", height: "570", visibility:"visible" });
		$(obj).fadeIn("normal");
		});
 }

  function registerFail(errorMsg){
	enableSubmitBtn();
	$("#send").parent().append("<span class='tishi pass_reg_err'>"+errorMsg+"</span>");	
 }